package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.domain.STestPaper;
import com.zhentao.result.Result;
import com.zhentao.service.STestPaperService;
import com.zhentao.mapper.STestPaperMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author 86150
* @description 针对表【s_test_paper】的数据库操作Service实现
* @createDate 2024-07-24 09:46:10
*/
@Service
public class STestPaperServiceImpl extends ServiceImpl<STestPaperMapper, STestPaper>
    implements STestPaperService{

    @Resource
    private STestPaperMapper sTestPaperMapper;


    //删除单个考试试卷中对应的题目
    @Override
    public Result delQuestionById(Integer qid, Integer eid) {
        QueryWrapper<STestPaper> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("question_id",qid);
        queryWrapper.eq("testinfo_id",eid);
        STestPaper sTestPaper = this.sTestPaperMapper.selectOne(queryWrapper);
        int i = this.sTestPaperMapper.deleteById(sTestPaper);
        return Result.OK(i);
    }

    //精准添加考试题目
    @Override
    public Result addQuestion(Integer[] qid, Integer eid) {
        for (Integer i : qid){
            STestPaper sTestPaper = new STestPaper();
            sTestPaper.setQuestionId(i);
            sTestPaper.setTestinfoId(eid);
            this.sTestPaperMapper.insert(sTestPaper);
        }
        return Result.OK();
    }
}




